package com.atguigu.tingshu.search.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolExecutorConfig {


    /**
     * 核心线程数 = n + 1    io:2n    n:cpu核数
     * @return
     */
    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(8,
                20,
                3,
                TimeUnit.SECONDS,  //时间单位
                new ArrayBlockingQueue<>(1000) //阻塞队列
//                Executors.defaultThreadFactory(), //线程工厂
//                new ThreadPoolExecutor.CallerRunsPolicy();  //拒绝策略 4种
        );
    }

}
